/*
 *  Copyright 2010 UPF Telecos 4th group G.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package edu.upf.userinterface.impl;

import edu.upf.content.DescriptionContent;
import edu.upf.content.ImageObject;
import edu.upf.content.Video;
import edu.upf.core.ClientLogic;
import edu.upf.core.User;
import edu.upf.editor.EditorListModel;
import edu.upf.editor.ImageFilters;
import edu.upf.editor.ImagePanel;
import edu.upf.editor.JAIConvolvePanel;
import edu.upf.editor.JPGsave;
import edu.upf.exceptions.GUIException;
import edu.upf.exceptions.UnopenedImageException;
import edu.upf.network.ContentTransfer;
import edu.upf.userinterface.UserInterface;
import edu.upf.utils.Definitions;
import edu.upf.utils.LogSystem;
import edu.upf.viewer.ViewerFrame;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.imageio.ImageIO;
import javax.media.jai.PlanarImage;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.tree.TreePath;

/**
 * Class that presents a graphical interface for the media sharing software
 * @author netjois
 */
public class GraphicInterface extends JFrame implements UserInterface, Definitions {

    private ClientLogic clientLogic;
    private DefaultListModel contactModel;
    private List<BufferedImage> editorCacheImages;
    private int currentImage;
    private int oldImagesNumber;
    private ResultTableModel resultTableModel;
    private DownloadsTableModel downloadsTableModel;
    private LibraryTableModel libraryTableModel;
    private EditorListModel editorListModel;
    private File editedImage;
    private File originalImage;
    private LogSystem log;
    private ImageTextCellRenderer imageCellRenderer;
    private int currentLibraryColumnNumber;
    private File sharedfolder;
    private ViewUpdater viewUpdater;
    private Properties properties;

    /**
     * Creates new form GraphicInterface, receives a client logic object for
     * callbacks
     * @param clientLogic
     */
    public GraphicInterface(ClientLogic clientLogic) {
        this.clientLogic = clientLogic;
        contactModel = new DefaultListModel();
        editorListModel = new EditorListModel();
        resultTableModel = new ResultTableModel();
        downloadsTableModel = new DownloadsTableModel();
        libraryTableModel = new LibraryTableModel();
        log = new LogSystem(GraphicInterface.class);
        initComponents();
        contactList.setCellRenderer(new ContactListCellRenderer());
        this.setIconImage(new ImageIcon(getClass().getResource("/logos/jMedia_mascota.png")).getImage());
        viewUpdater = new ViewUpdater(this);
        viewUpdater.start();
        initLoginConfig();
        editorCacheImages = new ArrayList();
        currentImage = NO_IMAGES;
        oldImagesNumber = 0;
    }

    /**
     * Show the contents inside the loaded components
     */
    @Override
    public void showContents() {
        initSharedFolder();
        initTableModels();
        initMouseListen();
        initMediaLibrary();
    }

    private void initLoginConfig() {
        properties = new Properties();
        try {
            properties.load(getClass().getResourceAsStream(SETTINGS_PROPERTIES));
        } catch (IOException ex) {
            clientLogic.showExceptionMessage(ex, WARNING);
        }
        String login = properties.getProperty(LOGIN_USER);
        String pass = properties.getProperty(PASS_USER);

        if (login != null && pass != null) {
            userField.setText(login);
            passField.setText(pass);
            if (!login.equals(EMPTY)) {
                rememberLoginCheck.setSelected(true);
            }
            if (!pass.equals(EMPTY)) {
                rememberPassCheck.setSelected(true);
            }
        }
    }

    private void initTableModels() {

        resultTable.setRowHeight(THUMBHEIGHT);
        resultTable.getColumnModel().getColumn(RESULT_THUMB_COLUM).setCellRenderer(new ThumbnailCellRenderer());
        resultTable.getColumnModel().getColumn(RESULT_THUMB_COLUM).setPreferredWidth(THUMBWIDTH);
        resultTable.getColumnModel().getColumn(RESULT_POPUL_COLUMN).setPreferredWidth(THUMBWIDTH);
        resultTable.setColumnSelectionAllowed(false);

        downloadsTable.getColumnModel().getColumn(PROGRESS_COLUMN).setCellRenderer(new ProgressBarCellRenderer());
        downloadsTable.getColumnModel().getColumn(PROGRESS_COLUMN).setPreferredWidth(BAR_LENGTH);
    }

    private void initMediaLibrary() {
        libraryScrollPane.setColumnHeaderView(null);
        libraryTableModel = new LibraryTableModel();
        imageCellRenderer = new ImageTextCellRenderer();
        libraryTable.setModel(libraryTableModel);
        libraryTable.setRowHeight(LIB_CELL_SIZE);
        currentLibraryColumnNumber = DEFAULT_COLUMN_NUM;
        updateMediaLibrary();
    }

    private void initSharedFolder() {
        sharedfolder = new File("Shared_Folder");
        sharedfolder.mkdir();
        File downloadsfolder = new File("Shared_Folder/Downloads");
        downloadsfolder.mkdir();
        updateAlbumListView();
    }

    public void updateMediaLibrary() {
        List datalist = clientLogic.getSharedContent("");
        libraryTableModel.setContent(datalist);
        updateMediaLibraryView();
    }

    private void updateMediaLibraryView() {

        int columns = libraryTable.getWidth() / LIB_CELL_SIZE;

        if (columns != currentLibraryColumnNumber) {
            currentLibraryColumnNumber = columns;
            libraryTableModel.setColumns(columns);

            TableColumnModel columnModel = libraryTable.getColumnModel();
            TableColumn tableColumn;
            for (int i = 0; i < columns; i++) {
                tableColumn = columnModel.getColumn(i);
                tableColumn.setPreferredWidth(LIB_THUMB_W);
                tableColumn.setCellRenderer(imageCellRenderer);
            }

        }
    }

    @Override
    public void addTransfer(ContentTransfer transfer) {
        downloadsTableModel.addTransfer(transfer);
    }

    /* This method is called from within the constructor to,initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPane = new javax.swing.JTabbedPane();
        mainPanel = new javax.swing.JPanel();
        jScrollPane10 = new javax.swing.JScrollPane();
        downloadsTable = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        rememberLoginCheck = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        passField = new javax.swing.JPasswordField();
        userField = new javax.swing.JFormattedTextField();
        statusLabel = new javax.swing.JLabel();
        loginButton = new javax.swing.JButton();
        rememberPassCheck = new javax.swing.JCheckBox();
        connectionIcon = new javax.swing.JLabel();
        clearCompletedButton = new javax.swing.JButton();
        libraryPanel = new javax.swing.JPanel();
        albumScrollPane = new javax.swing.JScrollPane();
        albumList = new javax.swing.JList();
        jLabel5 = new javax.swing.JLabel();
        newAlbumButton = new javax.swing.JButton();
        addMediaButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        libraryViewButton = new javax.swing.JButton();
        editButton = new javax.swing.JButton();
        annotateButton = new javax.swing.JButton();
        changeAlbumButton = new javax.swing.JButton();
        jSeparator6 = new javax.swing.JSeparator();
        libraryScrollPane = new javax.swing.JScrollPane();
        libraryTable = new javax.swing.JTable();
        editAlbumButton = new javax.swing.JButton();
        deleteMediaButton = new javax.swing.JButton();
        chatPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        contactList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        eventsLogArea = new javax.swing.JTextArea();
        startChatButton = new javax.swing.JButton();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jSeparator7 = new javax.swing.JSeparator();
        searchPanel = new javax.swing.JPanel();
        basicSearchButton = new javax.swing.JButton();
        basicSearchLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        searchResultLabel = new javax.swing.JLabel();
        categorySearchLabel = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        ontologyTree = new javax.swing.JTree();
        advancedSearchLabel = new javax.swing.JLabel();
        optionSearchBox = new javax.swing.JComboBox();
        newsSearchButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        categorySearchButton = new javax.swing.JButton();
        downloadButton = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        resultTable = new javax.swing.JTable();
        searchViewButon = new javax.swing.JButton();
        mediaTypeBox = new javax.swing.JComboBox();
        jSeparator8 = new javax.swing.JSeparator();
        basicSearchField = new javax.swing.JTextField();
        newsSearchField = new javax.swing.JTextField();
        categorySearchField = new javax.swing.JTextField();
        editionPanel = new javax.swing.JPanel();
        openEditorButton = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane11 = new javax.swing.JScrollPane();
        editList = new javax.swing.JList();
        jLabel11 = new javax.swing.JLabel();
        saveEditorButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator5 = new javax.swing.JSeparator();
        imageScrollPane = new javax.swing.JScrollPane();
        nameEditorLabel = new javax.swing.JLabel();
        sizeEditorLabel = new javax.swing.JLabel();
        jSeparator10 = new javax.swing.JSeparator();
        undoEditorButton = new javax.swing.JButton();
        redoEditorButton = new javax.swing.JButton();
        applyEditorButton = new javax.swing.JButton();
        controlPanel = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jSeparator9 = new javax.swing.JSeparator();
        applyVLCPathButton = new javax.swing.JButton();
        vlcPathField = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jSeparator11 = new javax.swing.JSeparator();
        jLabel17 = new javax.swing.JLabel();
        existPathField = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        applyExistPathButton = new javax.swing.JButton();
        jSeparator12 = new javax.swing.JSeparator();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel24 = new javax.swing.JLabel();
        vlcFeedbackLabel = new javax.swing.JLabel();
        existFeedbackLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("jMedia");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        tabbedPane.setFont(new java.awt.Font("DejaVu Sans", 0, 14));

        downloadsTable.setModel(downloadsTableModel);
        downloadsTable.setShowHorizontalLines(false);
        downloadsTable.setShowVerticalLines(false);
        jScrollPane10.setViewportView(downloadsTable);

        jLabel7.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel7.setText("Downloads list");

        jLabel8.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel8.setText("Login status");

        jSeparator4.setOrientation(javax.swing.SwingConstants.VERTICAL);

        rememberLoginCheck.setText("Remember me");

        jLabel3.setText("Password");

        jLabel2.setText("Username");

        statusLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        statusLabel.setText("Current status: Disconnected");

        loginButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/login20px.png"))); // NOI18N
        loginButton.setText("Login");
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginButtonActionPerformed(evt);
            }
        });

        rememberPassCheck.setText("Remember password");

        connectionIcon.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        connectionIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/logos/talk_logo_small.png"))); // NOI18N
        connectionIcon.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/logos/talk_logo_small.png"))); // NOI18N
        connectionIcon.setIconTextGap(0);

        clearCompletedButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/clean20px.png"))); // NOI18N
        clearCompletedButton.setText("Clear completed");
        clearCompletedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearCompletedButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel8))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(93, 93, 93)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(24, 24, 24)
                                .addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(userField, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                                .addComponent(passField)
                                .addComponent(rememberLoginCheck)
                                .addComponent(rememberPassCheck)
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGap(38, 38, 38)
                                    .addComponent(jLabel2)
                                    .addGap(33, 33, 33)))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(42, 42, 42)
                                .addComponent(jLabel3))))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(connectionIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)
                    .addComponent(clearCompletedButton)
                    .addComponent(jLabel7))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(statusLabel)
                                .addGap(12, 12, 12)
                                .addComponent(connectionIcon)
                                .addGap(32, 32, 32)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(userField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(passField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(rememberLoginCheck)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(rememberPassCheck)
                                .addGap(41, 41, 41)
                                .addComponent(loginButton))
                            .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(clearCompletedButton)))
                .addContainerGap())
        );

        tabbedPane.addTab("Main Panel", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/jMedia20px.png")), mainPanel); // NOI18N

        albumList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        albumList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                albumListValueChanged(evt);
            }
        });
        albumScrollPane.setViewportView(albumList);

        jLabel5.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel5.setText("Albums");

        newAlbumButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/new_album.png"))); // NOI18N
        newAlbumButton.setText("New Album");
        newAlbumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newAlbumButtonActionPerformed(evt);
            }
        });

        addMediaButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/new_media.png"))); // NOI18N
        addMediaButton.setText("Add");
        addMediaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addMediaButtonActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel6.setText("Media");

        libraryViewButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/view.png"))); // NOI18N
        libraryViewButton.setText("View");
        libraryViewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                libraryViewButtonActionPerformed(evt);
            }
        });

        editButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/panel_icons/edition20px.png"))); // NOI18N
        editButton.setText("Edit");
        editButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editButtonActionPerformed(evt);
            }
        });

        annotateButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/annotate.png"))); // NOI18N
        annotateButton.setText("Annotate");
        annotateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                annotateButtonActionPerformed(evt);
            }
        });

        changeAlbumButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/change_folder.png"))); // NOI18N
        changeAlbumButton.setText("Change Album");
        changeAlbumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeAlbumButtonActionPerformed(evt);
            }
        });

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);

        libraryTable.setBackground(new java.awt.Color(240, 240, 240));
        libraryTable.setModel(libraryTableModel);
        libraryTable.setCellSelectionEnabled(true);
        libraryTable.setGridColor(new java.awt.Color(240, 240, 240));
        libraryTable.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                libraryTableComponentResized(evt);
            }
        });
        libraryScrollPane.setViewportView(libraryTable);

        editAlbumButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/edit_folder20px.png"))); // NOI18N
        editAlbumButton.setText("Edit Album");
        editAlbumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editAlbumButtonActionPerformed(evt);
            }
        });

        deleteMediaButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/deleteMedia.png"))); // NOI18N
        deleteMediaButton.setText("Delete");
        deleteMediaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteMediaButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout libraryPanelLayout = new javax.swing.GroupLayout(libraryPanel);
        libraryPanel.setLayout(libraryPanelLayout);
        libraryPanelLayout.setHorizontalGroup(
            libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(libraryPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(libraryPanelLayout.createSequentialGroup()
                        .addComponent(newAlbumButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(editAlbumButton))
                    .addComponent(albumScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(libraryScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE)
                    .addGroup(libraryPanelLayout.createSequentialGroup()
                        .addComponent(libraryViewButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(addMediaButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(deleteMediaButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(changeAlbumButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(editButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(annotateButton)))
                .addContainerGap())
        );
        libraryPanelLayout.setVerticalGroup(
            libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(libraryPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, libraryPanelLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(libraryScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(libraryViewButton)
                            .addComponent(addMediaButton)
                            .addComponent(deleteMediaButton)
                            .addComponent(changeAlbumButton)
                            .addComponent(editButton)
                            .addComponent(annotateButton)))
                    .addComponent(jSeparator6, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addGroup(libraryPanelLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(albumScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(newAlbumButton)
                            .addComponent(editAlbumButton))))
                .addContainerGap())
        );

        tabbedPane.addTab("Media library", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/library20px.png")), libraryPanel); // NOI18N

        contactList.setBackground(new java.awt.Color(254, 254, 254));
        contactList.setModel(contactModel);
        jScrollPane1.setViewportView(contactList);

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel1.setText("Contact list");

        jLabel4.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel4.setText("Latest events");

        eventsLogArea.setBackground(new java.awt.Color(253, 251, 227));
        eventsLogArea.setColumns(20);
        eventsLogArea.setEditable(false);
        eventsLogArea.setRows(5);
        jScrollPane2.setViewportView(eventsLogArea);

        startChatButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/chat20px.png"))); // NOI18N
        startChatButton.setText("Start chat");
        startChatButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startChatButtonActionPerformed(evt);
            }
        });

        jCheckBox3.setSelected(true);
        jCheckBox3.setText("Show system events");

        jCheckBox4.setSelected(true);
        jCheckBox4.setText("Show messaging events");

        jSeparator7.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout chatPanelLayout = new javax.swing.GroupLayout(chatPanel);
        chatPanel.setLayout(chatPanelLayout);
        chatPanelLayout.setHorizontalGroup(
            chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chatPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addGap(94, 94, 94)
                        .addComponent(startChatButton, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addComponent(jCheckBox4)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBox3)))
                .addContainerGap())
        );
        chatPanelLayout.setVerticalGroup(
            chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chatPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE))
                    .addComponent(jSeparator7, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, chatPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startChatButton)
                    .addComponent(jCheckBox4)
                    .addComponent(jCheckBox3))
                .addContainerGap())
        );

        tabbedPane.addTab("Chat", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/chat20px.png")), chatPanel); // NOI18N

        basicSearchButton.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        basicSearchButton.setText("Search");
        basicSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                basicSearchButtonActionPerformed(evt);
            }
        });

        basicSearchLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        basicSearchLabel.setText("Basic search");

        searchResultLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        searchResultLabel.setText("Search results");

        categorySearchLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        categorySearchLabel.setText("Category search");

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Places");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Europe");
        javax.swing.tree.DefaultMutableTreeNode treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Germany");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Spain");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("France");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Italy");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Holland");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Portugal");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("United Kingdom");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Sweden");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Other Europe");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Africa");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Tunez");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Algeria");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Morocco");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("South Africa");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Other Africa");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Asia");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("India");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("China");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Singapore");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Japan");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Other Asia");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("America");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Usa");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Canada");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Brazil");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Argentina");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Mexico");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Other America");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Oceania");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Australia");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("New zeland");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Other Oceania");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Events");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sport");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Natural");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sociological");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Fashion");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Other Events");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Fauna");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Mammal");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ave");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Amphibian");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Reptile");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Fish");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Other animals");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Flora");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Tree");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Bus");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Herbs");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Flowers");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Other Flora");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Character");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Politics");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sportist");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Scientist");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Heart characer");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Artist");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Film character");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Literature character");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Technology character");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Medicine character");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Fashion character");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Tv character");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Musician");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Economist");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Teams");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Other characters");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Devices");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Medicine Devices");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Science Devices");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Technology Devices");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sport Devices");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Other Devices");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Transportation");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Car");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Cycling");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Motorcycle");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Train");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Tram");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Bus");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Underground");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Plain");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Boat");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Other Transports");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        ontologyTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        ontologyTree.setRootVisible(false);
        jScrollPane5.setViewportView(ontologyTree);

        advancedSearchLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        advancedSearchLabel.setText("News search");

        optionSearchBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Search in paragraph", "Search in title", "Search in article" }));

        newsSearchButton.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        newsSearchButton.setText("Search");
        newsSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newsSearchButtonActionPerformed(evt);
            }
        });

        categorySearchButton.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        categorySearchButton.setText("Search");
        categorySearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                categorySearchButtonActionPerformed(evt);
            }
        });

        downloadButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/download.png"))); // NOI18N
        downloadButton.setText("Download");
        downloadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downloadButtonActionPerformed(evt);
            }
        });

        resultTable.setBackground(new java.awt.Color(254, 254, 254));
        resultTable.setModel(resultTableModel);
        resultTable.setGridColor(new java.awt.Color(254, 254, 254));
        resultTable.setIntercellSpacing(new java.awt.Dimension(0, 0));
        resultTable.setSelectionBackground(new java.awt.Color(217, 217, 217));
        resultTable.setSelectionForeground(new java.awt.Color(1, 1, 1));
        resultTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        resultTable.setShowHorizontalLines(false);
        resultTable.setShowVerticalLines(false);
        jScrollPane4.setViewportView(resultTable);

        searchViewButon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/view.png"))); // NOI18N
        searchViewButon.setText("View");
        searchViewButon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchViewButonActionPerformed(evt);
            }
        });

        mediaTypeBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Image", "Video" }));

        jSeparator8.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
        searchPanel.setLayout(searchPanelLayout);
        searchPanelLayout.setHorizontalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(categorySearchLabel)
                    .addComponent(advancedSearchLabel)
                    .addComponent(basicSearchLabel)
                    .addComponent(mediaTypeBox, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, searchPanelLayout.createSequentialGroup()
                            .addComponent(basicSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(basicSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(categorySearchField, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(categorySearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(newsSearchField)
                            .addComponent(optionSearchBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(newsSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator8, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(searchResultLabel)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(searchViewButon, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(downloadButton))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 523, Short.MAX_VALUE))
                .addContainerGap())
        );
        searchPanelLayout.setVerticalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(searchResultLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE)
                        .addGap(11, 11, 11)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(searchViewButon)
                            .addComponent(downloadButton)))
                    .addComponent(jSeparator8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(basicSearchLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(basicSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(basicSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addComponent(mediaTypeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(advancedSearchLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(newsSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(newsSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addComponent(optionSearchBox, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(categorySearchLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(categorySearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(categorySearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)))
                .addContainerGap())
        );

        tabbedPane.addTab("Search", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/search20px.png")), searchPanel); // NOI18N

        openEditorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/open.png"))); // NOI18N
        openEditorButton.setText("Open");
        openEditorButton.setName("openEditorButton"); // NOI18N
        openEditorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openEditorButtonActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel9.setText("Actions");

        jLabel10.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel10.setText("Filters");

        editList.setModel(editorListModel);
        editList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane11.setViewportView(editList);

        jLabel11.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel11.setText("Image information");

        saveEditorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/save.png"))); // NOI18N
        saveEditorButton.setText("Save");
        saveEditorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveEditorButtonActionPerformed(evt);
            }
        });

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        nameEditorLabel.setText("Name:");

        sizeEditorLabel.setText("Size:");

        undoEditorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/undo.png"))); // NOI18N
        undoEditorButton.setText("Undo");
        undoEditorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                undoEditorButtonActionPerformed(evt);
            }
        });

        redoEditorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/redo.png"))); // NOI18N
        redoEditorButton.setText("Redo");
        redoEditorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                redoEditorButtonActionPerformed(evt);
            }
        });

        applyEditorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/accept20px.png"))); // NOI18N
        applyEditorButton.setText("Apply");
        applyEditorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyEditorButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout editionPanelLayout = new javax.swing.GroupLayout(editionPanel);
        editionPanel.setLayout(editionPanelLayout);
        editionPanelLayout.setHorizontalGroup(
            editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editionPanelLayout.createSequentialGroup()
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane11, 0, 0, Short.MAX_VALUE)
                            .addComponent(jLabel9)
                            .addComponent(sizeEditorLabel)
                            .addGroup(editionPanelLayout.createSequentialGroup()
                                .addComponent(openEditorButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(saveEditorButton))
                            .addGroup(editionPanelLayout.createSequentialGroup()
                                .addComponent(undoEditorButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(redoEditorButton))
                            .addComponent(jLabel11)
                            .addComponent(nameEditorLabel)
                            .addComponent(jLabel10)))
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(applyEditorButton))
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator5, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator10, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(imageScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 688, Short.MAX_VALUE)
                .addContainerGap())
        );
        editionPanelLayout.setVerticalGroup(
            editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imageScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(12, 12, 12)
                        .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(openEditorButton)
                            .addComponent(saveEditorButton))
                        .addGap(12, 12, 12)
                        .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(undoEditorButton)
                            .addComponent(redoEditorButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator10, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(nameEditorLabel)
                        .addGap(9, 9, 9)
                        .addComponent(sizeEditorLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane11, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(applyEditorButton)))
                .addContainerGap())
        );

        tabbedPane.addTab("Image edition", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/edition20px.png")), editionPanel); // NOI18N

        jLabel12.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/thumb_icons/VLC_icon.png"))); // NOI18N
        jLabel12.setText("Video configuration");
        jLabel12.setFocusable(false);
        jLabel12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel12.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        applyVLCPathButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/accept20px.png"))); // NOI18N
        applyVLCPathButton.setText("Apply");
        applyVLCPathButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyVLCPathButtonActionPerformed(evt);
            }
        });

        vlcPathField.setText("vlc");

        jLabel13.setText("VLC path: ");

        jLabel14.setText("This software uses VLC media player to show video content. Not already installed? See help section");

        jLabel15.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/thumb_icons/about_thumb.png"))); // NOI18N
        jLabel15.setText("About jMedia");
        jLabel15.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel15.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        jLabel16.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/thumb_icons/exist_logo.png"))); // NOI18N
        jLabel16.setText("DB configuration");
        jLabel16.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel16.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        jLabel17.setText("This software uses eXist XML database to organize your library. Not already installed? See help section");

        existPathField.setText("eXist");

        jLabel18.setText("eXist path: ");

        applyExistPathButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/accept20px.png"))); // NOI18N
        applyExistPathButton.setText("Apply");
        applyExistPathButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyExistPathButtonActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/thumb_icons/upf_logo.png"))); // NOI18N
        jLabel19.setText("About us");
        jLabel19.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel19.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        jLabel20.setText("jMedia is a P2P distributed application which allows the user to share, edit and annotate digital pictures.");

        jLabel21.setText("Version: 1.0.0");

        jLabel22.setText("It is written in java and uses smack, swing, xmldb and commons-logging libraries.");

        jLabel23.setText("Help:");

        jButton3.setForeground(new java.awt.Color(1, 1, 1));
        jButton3.setText("<html><a href=\"www.upf.edu\">Project documentation</a><html>");
        jButton3.setBorder(null);
        jButton3.setBorderPainted(false);

        jLabel24.setText("This project has been done by group G of the fourth year of Telecom. Engineering at UPF at 2010.");

        vlcFeedbackLabel.setForeground(new java.awt.Color(255, 0, 0));
        vlcFeedbackLabel.setText("Path not configured");

        existFeedbackLabel.setForeground(new java.awt.Color(255, 0, 0));
        existFeedbackLabel.setText("Path not configured");

        javax.swing.GroupLayout controlPanelLayout = new javax.swing.GroupLayout(controlPanel);
        controlPanel.setLayout(controlPanelLayout);
        controlPanelLayout.setHorizontalGroup(
            controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelLayout.createSequentialGroup()
                .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel12)
                        .addGap(18, 18, 18)
                        .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(controlPanelLayout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(vlcPathField, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(applyVLCPathButton)
                                .addGap(18, 18, Short.MAX_VALUE)
                                .addComponent(vlcFeedbackLabel))
                            .addComponent(jLabel14)))
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel16)
                        .addGap(18, 18, 18)
                        .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(controlPanelLayout.createSequentialGroup()
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(existPathField, javax.swing.GroupLayout.PREFERRED_SIZE, 402, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(applyExistPathButton)
                                .addGap(18, 18, 18)
                                .addComponent(existFeedbackLabel))
                            .addComponent(jLabel17)))
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel15)
                        .addGap(42, 42, 42)
                        .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel20)
                            .addGroup(controlPanelLayout.createSequentialGroup()
                                .addComponent(jLabel21)
                                .addGap(43, 43, 43)
                                .addComponent(jLabel23)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel22)))
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jLabel19)
                        .addGap(58, 58, 58)
                        .addComponent(jLabel24))
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator9, javax.swing.GroupLayout.DEFAULT_SIZE, 864, Short.MAX_VALUE))
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator11, javax.swing.GroupLayout.DEFAULT_SIZE, 864, Short.MAX_VALUE))
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator12, javax.swing.GroupLayout.DEFAULT_SIZE, 864, Short.MAX_VALUE)))
                .addContainerGap())
        );
        controlPanelLayout.setVerticalGroup(
            controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel12)
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addGap(18, 18, 18)
                        .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(vlcPathField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(applyVLCPathButton)
                            .addComponent(vlcFeedbackLabel))))
                .addGap(18, 18, 18)
                .addComponent(jSeparator9, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel16)
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addGap(18, 18, 18)
                        .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(existPathField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18)
                            .addComponent(applyExistPathButton)
                            .addComponent(existFeedbackLabel))))
                .addGap(18, 18, 18)
                .addComponent(jSeparator11, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel15)
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel21)
                            .addComponent(jLabel23)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(jSeparator12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addGroup(controlPanelLayout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jLabel24)))
                .addContainerGap(46, Short.MAX_VALUE))
        );

        tabbedPane.addTab("Config & Help", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/configuration20px.png")), controlPanel); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 892, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void downloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadButtonActionPerformed
        int row = resultTable.getSelectedRow();
        if (row >= 0) {
            DescriptionContent selectedContent = resultTableModel.getDescriptionContentAt(row);
            clientLogic.sendUserContentRequest(selectedContent, false);
            tabbedPane.setSelectedIndex(MAIN_PANEL_POS);
        } else {
            clientLogic.showExceptionMessage(new GUIException("Please, select the media you want to download."), INFO);
        }
}//GEN-LAST:event_downloadButtonActionPerformed

    private void categorySearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_categorySearchButtonActionPerformed
        TreePath treePath = (ontologyTree.getSelectionPath());
        if (treePath == null) {
            log.addInfoLog("There is no selected category, performing basic search");
            return;
        }

        String search = categorySearchField.getText();
        String category = treePath.getLastPathComponent().toString().toLowerCase();
        String subtype = null;
        String parameters = null;

        if (search.equals("")) {
            subtype = SIMPLE;
            parameters = category;
        } else {
            subtype = PLUS;
            parameters = category + SPLITTER + search;
        }
        clientLogic.sendSearchQuery(CATEGORY, subtype, parameters);
}//GEN-LAST:event_categorySearchButtonActionPerformed

    private void newsSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newsSearchButtonActionPerformed
        String option = ((String) optionSearchBox.getSelectedItem()).toLowerCase();
        String subtype = null;
        if (option.matches(".*paragraph$")) {
            subtype = PARAGRAPH;
        } else if (option.matches(".*article$")) {
            subtype = ARTICLE;
        } else if (option.matches(".*title$")) {
            subtype = TITLE;
        } else {
            return;
        }
        clientLogic.sendSearchQuery(NEWS, subtype, newsSearchField.getText());
}//GEN-LAST:event_newsSearchButtonActionPerformed

    private void basicSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_basicSearchButtonActionPerformed
        String subtype = ((String) mediaTypeBox.getSelectedItem()).toLowerCase();
        clientLogic.sendSearchQuery(BASIC, subtype, basicSearchField.getText());
}//GEN-LAST:event_basicSearchButtonActionPerformed

    private void startChatButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startChatButtonActionPerformed
        startChatWith(getSelectedUser());
}//GEN-LAST:event_startChatButtonActionPerformed

    private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed

        String test = loginButton.getText();
        if (test.equals("Login")) {
            clientLogic.login(userField.getText().toString().trim(), new String(passField.getPassword()).trim(), JMEDIA_RESOURCE);
            if (rememberLoginCheck.isSelected()) {
                properties.setProperty(LOGIN_USER, userField.getText());
            } else {
                properties.setProperty(LOGIN_USER, "");
            }
            if (rememberPassCheck.isSelected()) {
                properties.setProperty(PASS_USER, new String(passField.getPassword()));
            } else {
                properties.setProperty(PASS_USER, "");
            }
            try {
                URL url = getClass().getResource(SETTINGS_PROPERTIES);
                File file = new File(url.toURI());
                FileOutputStream fout = new FileOutputStream(file);
                properties.store(fout, null);
                fout.close();
            } catch (URISyntaxException ex) {
                clientLogic.showExceptionMessage(ex, WARNING);
            } catch (FileNotFoundException ex) {
                clientLogic.showExceptionMessage(ex, WARNING);
            } catch (IOException ex) {
                clientLogic.showExceptionMessage(ex, WARNING);
            }
        } else if (test.equals("Logout")) {
            clientLogic.logout();
        } else if (test.equals("Cancel")) {
            clientLogic.interruptLogin();
        }

        if (rememberLoginCheck.isSelected()) {
            properties.setProperty(LOGIN_USER, userField.getText());
        } else {
            properties.setProperty(LOGIN_USER, "");
        }
}//GEN-LAST:event_loginButtonActionPerformed

    private void openEditorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openEditorButtonActionPerformed

        JFileChooser openFileChooser = new JFileChooser();
        openFileChooser.setAcceptAllFileFilterUsed(false);
        ImageFilters imageFilters = new ImageFilters();
        openFileChooser.addChoosableFileFilter(imageFilters.getPNGFilter());
        openFileChooser.addChoosableFileFilter(imageFilters.getGIFFilter());
        openFileChooser.addChoosableFileFilter(imageFilters.getJPGFilter());
        int returnVal = openFileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            originalImage = openFileChooser.getSelectedFile();
            try {
                editorCacheImages.clear();
                editorCacheImages.add(ImageIO.read(originalImage));
                currentImage = INITIAL;
                showEditImage(editorCacheImages.get(currentImage));
            } catch (IOException ex) {
                clientLogic.showExceptionMessage(ex, WARNING);
            }
            nameEditorLabel.setText("Name: " + originalImage.getName());
            sizeEditorLabel.setText("Size: " + originalImage.length() / 1000 + " KB");
        }
}//GEN-LAST:event_openEditorButtonActionPerformed

    private void saveEditorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveEditorButtonActionPerformed

        JFileChooser saveFileChooser = new JFileChooser();
        saveFileChooser.setCurrentDirectory(new File("Shared_Folder"));
        saveFileChooser.setAcceptAllFileFilterUsed(false);
        ImageFilters imageFilters = new ImageFilters();
        saveFileChooser.addChoosableFileFilter(imageFilters.getJPGFilter());

        if (originalImage == null) {
            clientLogic.showExceptionMessage(new UnopenedImageException("There is no image opened"), INFO);
            return;
        }

        // Set to a default name for save.
        if (originalImage.getName() != null) {
            editedImage = new File(originalImage.getName());
        }
        saveFileChooser.setSelectedFile(editedImage);

        // Open chooser dialog
        int result = saveFileChooser.showSaveDialog(this);
        ImageQualityDialog imageQualityDialog;
        if (result == JFileChooser.APPROVE_OPTION) {
            editedImage = saveFileChooser.getSelectedFile();
            if (editedImage.exists()) {
                int response = JOptionPane.showConfirmDialog(null,
                        "Overwrite existing file?", "Confirm Overwrite",
                        JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.QUESTION_MESSAGE);
                if (response != JOptionPane.CANCEL_OPTION) {
                    imageQualityDialog = new ImageQualityDialog(this, true);
                    imageQualityDialog.setVisible(true);
                }
            } else {
                imageQualityDialog = new ImageQualityDialog(this, true);
                imageQualityDialog.setVisible(true);
            }
        }
    }//GEN-LAST:event_saveEditorButtonActionPerformed

    private void libraryTableComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_libraryTableComponentResized
        updateMediaLibraryView();
    }//GEN-LAST:event_libraryTableComponentResized

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        this.setVisible(false);
        clientLogic.closeVideoServer();
        clientLogic.stopDB();
    }//GEN-LAST:event_formWindowClosing

    private void libraryViewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_libraryViewButtonActionPerformed
        viewContent(getSelectedContent(), true);
    }//GEN-LAST:event_libraryViewButtonActionPerformed

    public DescriptionContent getSelectedContent() {
        int row = libraryTable.getSelectedRow();
        int col = libraryTable.getSelectedColumn();
        DescriptionContent selectedcontent = null;
        if (row == -1 || col == -1) {
            clientLogic.showExceptionMessage(new GUIException("Please, select a file of the Library before edditing or moving."), INFO);
        } else {
            selectedcontent = libraryTableModel.getContentAt(row, col);
        }
        return selectedcontent;
    }

    @Override
    public void viewContent(DescriptionContent dc, boolean local) {
        if (dc instanceof Video) {
            try {
                Video vid = (Video) dc;
                String ip = vid.getIP();
                String path = vid.getPath();
                String format = vid.getFormat();
                String vidname = vid.getName();
                clientLogic.openVideoClient(ip, path, format, vidname, local);
            } catch (InterruptedException ex) {
                log.addInfoLog(ex.getMessage());
            } catch (IOException ex) {
                log.addInfoLog(ex.getMessage());
                clientLogic.showExceptionMessage(ex, WARNING);
            }
        } else if (dc instanceof ImageObject && local) {
            showViewerImage(dc, false);
        } else if (dc instanceof ImageObject && !local) {
            clientLogic.sendUserContentRequest(dc, true);
        }
    }

    @Override
    public void showViewerImage(DescriptionContent content, boolean autodel){
        ViewerFrame frame = new ViewerFrame(content.getName()+"."+content.getFormat(),autodel);
        frame.showImage((ImageObject) content);
        frame.setVisible(true);    
    }

    private void searchViewButonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchViewButonActionPerformed
        int row = resultTable.getSelectedRow();
        if (row >= 0) {
            DescriptionContent selectedContent = resultTableModel.getDescriptionContentAt(row);
            viewContent(selectedContent, false);
            tabbedPane.setSelectedIndex(MAIN_PANEL_POS);
        } else {
            clientLogic.showExceptionMessage(new GUIException("Please, select the media you want to view."), INFO);
        }
    }//GEN-LAST:event_searchViewButonActionPerformed

    private void albumListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_albumListValueChanged
        if (!evt.getValueIsAdjusting()) {
            if ((String) albumList.getSelectedValue() != null) {
                List datalist = clientLogic.getSharedContent((String) albumList.getSelectedValue());
                libraryTableModel.setContent(datalist);
                updateMediaLibraryView();
            }
        }
    }//GEN-LAST:event_albumListValueChanged

    public void updateAlbumListView() {
        FilenameFilter filter = new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return !name.startsWith(".");
            }
        };

        String[] children = sharedfolder.list(filter);
        albumList.setModel(new AlbumListModel(children));
    }
    private void newAlbumButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newAlbumButtonActionPerformed
        NewAlbumDialog newAlbum = new NewAlbumDialog(this, true);
        String newalbumname = newAlbum.getNewAlbumName();
        if (newalbumname != null) {
            File newAlb = new File("Shared_Folder/" + newalbumname);
            newAlb.mkdir();
            updateAlbumListView();
        }
    }//GEN-LAST:event_newAlbumButtonActionPerformed

    private void addMediaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMediaButtonActionPerformed
        AddMedia added = new AddMedia(this, true);
        if (added.getFile()!= null){
            File addf = added.getFile();
            Long siz = addf.length();
            String size = siz.toString();
            String album = added.getAlbum();
            DescriptionContent add = clientLogic.createDescriptionContent("Shared_Folder/" + album + "/" + addf.getName());
            if (added.Add()) {
                clientLogic.addMedia(add, size);
                updateAlbumListView();
                updateMediaLibrary();
            }
        }
    }//GEN-LAST:event_addMediaButtonActionPerformed

    private void changeAlbumButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeAlbumButtonActionPerformed
        DescriptionContent selected = getSelectedContent();
        if (selected != null) {
            ChangeAlbumDialog ad = new ChangeAlbumDialog(this, true, selected);
            if (ad.getNewAlbum() != null) {
                String album = ad.getNewAlbum();
                if (ad.Change()) {
                    clientLogic.updateAlbum(selected, album);
                }
                updateAlbumListView();
                updateMediaLibrary();
            }
        }
    }//GEN-LAST:event_changeAlbumButtonActionPerformed

    private void deleteMediaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMediaButtonActionPerformed
        DescriptionContent selected = getSelectedContent();
        if (selected != null) {
            DeleteMediaDialog dm = new DeleteMediaDialog(this, true, selected);
            if (dm.Delete()) {
                clientLogic.deleteMedia(selected);
            }
            updateMediaLibrary();
        }
    }//GEN-LAST:event_deleteMediaButtonActionPerformed

    private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
        DescriptionContent selected = getSelectedContent();
        if (selected != null && selected instanceof ImageObject) {
            originalImage = new File(selected.getPath());
            try {
                editorCacheImages.clear();
                editorCacheImages.add(ImageIO.read(originalImage));
                currentImage = INITIAL;
                showEditImage(editorCacheImages.get(currentImage));
                nameEditorLabel.setText("Name: " + originalImage.getName());
                sizeEditorLabel.setText("Size: " + originalImage.length() / 1000 + " KB");

                tabbedPane.setSelectedIndex(EDITOR_PANEL_POS);

            } catch (IOException ex) {
                log.addInfoLog(ex.getMessage() + "Error while attempting to load the image");
            }
        } else {
            clientLogic.showExceptionMessage(new GUIException("Please, select the photo you want to edit. Video is not accepted."), INFO);
        }
    }//GEN-LAST:event_editButtonActionPerformed

    private void annotateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_annotateButtonActionPerformed
        DescriptionContent selected = getSelectedContent();
        if (selected != null) {
            TagWindow tw = new TagWindow(this, true);
            if (tw.isOntology()) {
                if (tw.getException() != null) {
                    clientLogic.showExceptionMessage(new GUIException(tw.getException()), INFO);
                } else {
                    String category = tw.getCategory();
                    clientLogic.updateOntology(selected, category);
                }
            } else if (tw.isFreeTag()) {
                String[] tags = tw.getTags();
                for (int i = 0; i < 2; i++) {
                    if (!tags[i].equals("")) {
                        clientLogic.addTag(selected, tags[i]);
                    }
                }
            }
            updateMediaLibrary();
        }
    }//GEN-LAST:event_annotateButtonActionPerformed

    private void clearCompletedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearCompletedButtonActionPerformed
        clearFinishedDownloads();
    }//GEN-LAST:event_clearCompletedButtonActionPerformed

    public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }

        // The directory is now empty so delete it
        return dir.delete();
    }

    private void editAlbumButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editAlbumButtonActionPerformed
        String selected = (String) albumList.getSelectedValue();
        EditAlbumDialog ead = new EditAlbumDialog(this, true);
        if (ead.isDelete()) {
            File album = new File("Shared_Folder/" + selected);
            deleteDir(album);
            clientLogic.deleteAlbum(selected);
        } else if (ead.isNewName()) {
            File album = new File("Shared_Folder/" + selected);
            album.renameTo(new File("Shared_Folder/" + ead.getNewName()));
            clientLogic.changeAlbum(selected, ead.getNewName());
        }
        updateMediaLibrary();
        updateAlbumListView();
    }//GEN-LAST:event_editAlbumButtonActionPerformed

    private void applyEditorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyEditorButtonActionPerformed

        if (!editList.isSelectionEmpty()) {
            int index = editList.getSelectedIndex();
            if (editorCacheImages.size() > 0) {
                for (int i = 0; i < oldImagesNumber; i++) {
                    editorCacheImages.remove(editorCacheImages.size() - 1);
                }
            }

            PlanarImage resultPlanarImage = (new JAIConvolvePanel().convolve(PlanarImage.wrapRenderedImage(editorCacheImages.get(currentImage)), index));
            editorCacheImages.add(resultPlanarImage.getAsBufferedImage());
            currentImage++;
            oldImagesNumber = 0;
            showEditImage(editorCacheImages.get(currentImage));
        }

    }//GEN-LAST:event_applyEditorButtonActionPerformed

    private void undoEditorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_undoEditorButtonActionPerformed
        if (currentImage > INITIAL) {
            currentImage--;
            oldImagesNumber++;
            showEditImage(editorCacheImages.get(currentImage));
        }
    }//GEN-LAST:event_undoEditorButtonActionPerformed

    private void redoEditorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_redoEditorButtonActionPerformed
        if (currentImage < editorCacheImages.size() - 1) {
            currentImage++;
            oldImagesNumber--;
            showEditImage(editorCacheImages.get(currentImage));
        }
    }//GEN-LAST:event_redoEditorButtonActionPerformed

    private void applyVLCPathButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyVLCPathButtonActionPerformed

        properties.setProperty("vlcpath", vlcPathField.getText());
        FileOutputStream fout = null;
        try {
            URL url = getClass().getResource(SETTINGS_PROPERTIES);
            fout = new FileOutputStream(new File(url.toURI()));
            properties.store(fout, "Last save: vlc path");
            fout.close();
        } catch (IOException ex) {
            clientLogic.showExceptionMessage(ex, WARNING);
        } catch (URISyntaxException ex) {
            clientLogic.showExceptionMessage(ex, WARNING);
        }

    }//GEN-LAST:event_applyVLCPathButtonActionPerformed

    private void applyExistPathButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyExistPathButtonActionPerformed
        properties.setProperty("existpath", existPathField.getText());
        FileOutputStream fout = null;
        try {
            URL url = getClass().getResource(SETTINGS_PROPERTIES);
            fout = new FileOutputStream(new File(url.toURI()));
            properties.store(fout, "Last save: exist path");
            fout.close();
        } catch (IOException ex) {
            clientLogic.showExceptionMessage(ex, WARNING);
        } catch (URISyntaxException ex) {
            clientLogic.showExceptionMessage(ex, WARNING);
        }
    }//GEN-LAST:event_applyExistPathButtonActionPerformed

    public void showEditImage(BufferedImage img) {
        ImagePanel ip = new ImagePanel(img);
        imageScrollPane.getViewport().add(ip);
    }

    public void saveEditImage(int quality) throws FileNotFoundException, IOException {
        float value = (float) quality / 100.0f;
        new JPGsave(editedImage, PlanarImage.wrapRenderedImage(editorCacheImages.get(currentImage)), value);
    }

    @Override
    public void updateState(int state) {
        if (state == LOGGED_STATE) {
            connectionIcon.setIcon(new ImageIcon(getClass().getResource("/logos/logo_con.png")));
            statusLabel.setText("Current Status: Connected");
            loginButton.setText("Logout");
        } else if (state == LOGGING_STATE) {
            connectionIcon.setIcon(new ImageIcon(getClass().getResource("/logos/loading.gif")));
            statusLabel.setText("Current Status: Connecting...");
            loginButton.setText("Cancel");
        } else {
            connectionIcon.setIcon(new ImageIcon(getClass().getResource("/logos/talk_logo_small.png")));
            statusLabel.setText("Current Status: Disconnected");
            loginButton.setText("Login");
        }
    }

    @Override
    public void addUserToList(User user) {
        contactModel.addElement(user);
    }

    @Override
    public void updateUserList(User user) {
        contactModel.setElementAt(user, contactModel.indexOf(user));
    }

    @Override
    public void removeUserFromList(User user) {
        contactModel.removeElement(user);
    }

    @Override
    public void addResult(DescriptionContent receivedContent) {
        resultTableModel.addDescriptionContent(receivedContent);
    }

    @Override
    public void clearResults() {
        int rowNumber = 0;
        rowNumber = resultTable.getRowCount();
        for (int i = 0; i < rowNumber; i++) {
            resultTableModel.removeDescriptionContentAt(0);
        }
    }

    private void initMouseListen() {
        MouseListener mouseListener = new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    if (getSelectedUser() != null) {
                        startChatWith(getSelectedUser());
                    }
                }
            }
        };
        contactList.addMouseListener(mouseListener);
    }

    private String getSelectedUser() {
        int currentListPosition = contactList.getAnchorSelectionIndex();
        if (currentListPosition != -1) {
            return clientLogic.getContactMail(currentListPosition);
        }
        return null;
    }

    @Override
    public void startChatWith(String user) {
        clientLogic.openUserChat(user);
    }

    @Override
    public void userLog(String log) {
        eventsLogArea.append(new Date() + ": " + log + "\n");
    }

    @Override
    public void showExceptionMessage(String level, String exception, String trace) {
        ExceptionDialog dialog = new ExceptionDialog(this, true);
        dialog.setException(level, exception, trace);
        dialog.setVisible(true);
    }

    public void clearFinishedDownloads() {
        downloadsTableModel.clearCompleted();
    }

    @Override
    public void updateDownloads() {
        downloadsTableModel.refreshDownloadData();
    }

    public void showExistConfiguration(String path, boolean configured){
        existPathField.setText(path);
        if(configured){
            existFeedbackLabel.setText("Path correct");
            existFeedbackLabel.setForeground(new Color(0,220,0));
        }
    }

    public void showVLCConfiguration(String path, boolean configured){
        vlcPathField.setText(path);
        if(configured){
            vlcFeedbackLabel.setText("Path correct");
            vlcFeedbackLabel.setForeground(new Color(0,220,0));
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addMediaButton;
    private javax.swing.JLabel advancedSearchLabel;
    private javax.swing.JList albumList;
    private javax.swing.JScrollPane albumScrollPane;
    private javax.swing.JButton annotateButton;
    private javax.swing.JButton applyEditorButton;
    private javax.swing.JButton applyExistPathButton;
    private javax.swing.JButton applyVLCPathButton;
    private javax.swing.JButton basicSearchButton;
    private javax.swing.JTextField basicSearchField;
    private javax.swing.JLabel basicSearchLabel;
    private javax.swing.JButton categorySearchButton;
    private javax.swing.JTextField categorySearchField;
    private javax.swing.JLabel categorySearchLabel;
    private javax.swing.JButton changeAlbumButton;
    private javax.swing.JPanel chatPanel;
    private javax.swing.JButton clearCompletedButton;
    private javax.swing.JLabel connectionIcon;
    private javax.swing.JList contactList;
    private javax.swing.JPanel controlPanel;
    private javax.swing.JButton deleteMediaButton;
    private javax.swing.JButton downloadButton;
    private javax.swing.JTable downloadsTable;
    private javax.swing.JButton editAlbumButton;
    private javax.swing.JButton editButton;
    private javax.swing.JList editList;
    private javax.swing.JPanel editionPanel;
    private javax.swing.JTextArea eventsLogArea;
    private javax.swing.JLabel existFeedbackLabel;
    private javax.swing.JTextField existPathField;
    private javax.swing.JScrollPane imageScrollPane;
    private javax.swing.JButton jButton3;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator10;
    private javax.swing.JSeparator jSeparator11;
    private javax.swing.JSeparator jSeparator12;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JSeparator jSeparator9;
    private javax.swing.JPanel libraryPanel;
    private javax.swing.JScrollPane libraryScrollPane;
    private javax.swing.JTable libraryTable;
    private javax.swing.JButton libraryViewButton;
    private javax.swing.JButton loginButton;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JComboBox mediaTypeBox;
    private javax.swing.JLabel nameEditorLabel;
    private javax.swing.JButton newAlbumButton;
    private javax.swing.JButton newsSearchButton;
    private javax.swing.JTextField newsSearchField;
    private javax.swing.JTree ontologyTree;
    private javax.swing.JButton openEditorButton;
    private javax.swing.JComboBox optionSearchBox;
    private javax.swing.JPasswordField passField;
    private javax.swing.JButton redoEditorButton;
    private javax.swing.JCheckBox rememberLoginCheck;
    private javax.swing.JCheckBox rememberPassCheck;
    private javax.swing.JTable resultTable;
    private javax.swing.JButton saveEditorButton;
    private javax.swing.JPanel searchPanel;
    private javax.swing.JLabel searchResultLabel;
    private javax.swing.JButton searchViewButon;
    private javax.swing.JLabel sizeEditorLabel;
    private javax.swing.JButton startChatButton;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JTabbedPane tabbedPane;
    private javax.swing.JButton undoEditorButton;
    private javax.swing.JFormattedTextField userField;
    private javax.swing.JLabel vlcFeedbackLabel;
    private javax.swing.JTextField vlcPathField;
    // End of variables declaration//GEN-END:variables
}
